package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.FertilizerApplyCon;
import com.ruoyi.consume.service.IFertilizerApplyConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 化肥领用Controller
 *
 * @author ruoyi
 * @date 2021-07-23
 */
@Api("化肥领用")
@RestController
@RequestMapping("/consume/fertilizerap")
public class FertilizerApplyConController extends BaseController
{
    @Autowired
    private IFertilizerApplyConService fertilizerApplyService;

    /**
     * 查询化肥领用列表
     */
    @ApiOperation("查询化肥领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:list')")
    @GetMapping("/list")
    public TableDataInfo list(FertilizerApplyCon fertilizerApplyCon)
    {
        startPage();
        List<FertilizerApplyCon> list = fertilizerApplyService.selectFertilizerApplyList(fertilizerApplyCon);
        return getDataTable(list);
    }

    /**
     * 导出化肥领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:export')")
    @Log(title = "化肥领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FertilizerApplyCon fertilizerApplyCon)
    {
        List<FertilizerApplyCon> list = fertilizerApplyService.selectFertilizerApplyList(fertilizerApplyCon);
        ExcelUtil<FertilizerApplyCon> util = new ExcelUtil<FertilizerApplyCon>(FertilizerApplyCon.class);
        return util.exportExcel(list, "化肥领用数据");
    }

    /**
     * 获取化肥领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:query')")
    @GetMapping(value = "/{fertilizerApplyId}")
    public AjaxResult getInfo(@PathVariable("fertilizerApplyId") Long fertilizerApplyId)
    {
        return AjaxResult.success(fertilizerApplyService.selectFertilizerApplyById(fertilizerApplyId));
    }

    /**
     * 新增化肥领用
     */
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:add')")
    @Log(title = "化肥领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FertilizerApplyCon fertilizerApplyCon)
    {
        return toAjax(fertilizerApplyService.insertFertilizerApply(fertilizerApplyCon));
    }

    /**
     * 修改化肥领用
     */
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:edit')")
    @Log(title = "化肥领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FertilizerApplyCon fertilizerApplyCon)
    {
        return toAjax(fertilizerApplyService.updateFertilizerApply(fertilizerApplyCon));
    }

    /**
     * 删除化肥领用
     */
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:remove')")
    @Log(title = "化肥领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertilizerApplyIds}")
    public AjaxResult remove(@PathVariable Long[] fertilizerApplyIds)
    {
        return toAjax(fertilizerApplyService.deleteFertilizerApplyByIds(fertilizerApplyIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:amount')")
    @Log(title = "化肥领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody FertilizerApplyCon fertilizerApplyCon)
    {
        return toAjax(fertilizerApplyService.updateFertilizerAmount(fertilizerApplyCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:consu')")
    @Log(title = "化肥领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{fertilizerApplyId}")
    public AjaxResult consume(@PathVariable("fertilizerApplyId") Long fertilizerApplyId)
    {
        return toAjax(fertilizerApplyService.updateConsumeStatus(fertilizerApplyId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:fertilizerap:back')")
    @Log(title = "化肥领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{fertilizerApplyId}")
    public AjaxResult back(@PathVariable("fertilizerApplyId") Long fertilizerApplyId)
    {
        return toAjax(fertilizerApplyService.updateApprovalStatus(fertilizerApplyId));
    }
}
